/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.thinktank.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.annotation.rest.AnonymousPostMapping;
import com.fzhucc.modules.thinktank.domain.LeaderMsgBox;
import com.fzhucc.modules.thinktank.domain.dto.CompanyBoxSeekDto;
import com.fzhucc.modules.thinktank.domain.dto.LeaderBoxSeekDto;
import com.fzhucc.modules.thinktank.service.LeaderMsgBoxService;
import com.fzhucc.modules.thinktank.domain.dto.LeaderMsgBoxQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2023-03-10
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "智库：产业龙头咨询留言箱管理")
@RequestMapping("/api/leaderMsgBox")
public class LeaderMsgBoxController {

    private final LeaderMsgBoxService leaderMsgBoxService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('leaderMsgBox:list')")
    public void exportLeaderMsgBox(HttpServletResponse response, LeaderMsgBoxQueryCriteria criteria) throws IOException {
        leaderMsgBoxService.download(leaderMsgBoxService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询咨询产业龙头留言箱")
    @ApiOperation("查询咨询产业龙头留言箱")
    @PreAuthorize("@el.check('leaderMsgBox:list')")
    public ResponseEntity<Object> queryLeaderMsgBox(LeaderMsgBoxQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(leaderMsgBoxService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除咨询产业龙头留言箱")
    @ApiOperation("删除咨询产业龙头留言箱")
    @PreAuthorize("@el.check('leaderMsgBox:del')")
    public ResponseEntity<Object> deleteLeaderMsgBox(@RequestBody Integer[] ids) {
        leaderMsgBoxService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("咨询产业龙头")
    @ApiOperation("咨询产业龙头")
    @AnonymousPostMapping(value = "/seek")
    public ResponseEntity<Object> seek(@Validated @RequestBody LeaderBoxSeekDto resources) {
        return new ResponseEntity<>(leaderMsgBoxService.seek(resources), HttpStatus.OK);
    }
}